﻿USE [master]
GO
/****** Object:  Database [CheckersDB]    Script Date: 20/08/2013 22:35:42 ******/
CREATE DATABASE [CheckersDB] ON  PRIMARY 
( NAME = N'CheckersDB', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\CheckersDB.mdf' , SIZE = 3072KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
 LOG ON 
( NAME = N'CheckersDB_log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\CheckersDB_log.ldf' , SIZE = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
GO
ALTER DATABASE [CheckersDB] SET COMPATIBILITY_LEVEL = 100
GO
IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
begin
EXEC [CheckersDB].[dbo].[sp_fulltext_database] @action = 'enable'
end
GO
ALTER DATABASE [CheckersDB] SET ANSI_NULL_DEFAULT OFF 
GO
ALTER DATABASE [CheckersDB] SET ANSI_NULLS OFF 
GO
ALTER DATABASE [CheckersDB] SET ANSI_PADDING OFF 
GO
ALTER DATABASE [CheckersDB] SET ANSI_WARNINGS OFF 
GO
ALTER DATABASE [CheckersDB] SET ARITHABORT OFF 
GO
ALTER DATABASE [CheckersDB] SET AUTO_CLOSE ON 
GO
ALTER DATABASE [CheckersDB] SET AUTO_CREATE_STATISTICS ON 
GO
ALTER DATABASE [CheckersDB] SET AUTO_SHRINK OFF 
GO
ALTER DATABASE [CheckersDB] SET AUTO_UPDATE_STATISTICS ON 
GO
ALTER DATABASE [CheckersDB] SET CURSOR_CLOSE_ON_COMMIT OFF 
GO
ALTER DATABASE [CheckersDB] SET CURSOR_DEFAULT  GLOBAL 
GO
ALTER DATABASE [CheckersDB] SET CONCAT_NULL_YIELDS_NULL OFF 
GO
ALTER DATABASE [CheckersDB] SET NUMERIC_ROUNDABORT OFF 
GO
ALTER DATABASE [CheckersDB] SET QUOTED_IDENTIFIER OFF 
GO
ALTER DATABASE [CheckersDB] SET RECURSIVE_TRIGGERS OFF 
GO
ALTER DATABASE [CheckersDB] SET  ENABLE_BROKER 
GO
ALTER DATABASE [CheckersDB] SET AUTO_UPDATE_STATISTICS_ASYNC OFF 
GO
ALTER DATABASE [CheckersDB] SET DATE_CORRELATION_OPTIMIZATION OFF 
GO
ALTER DATABASE [CheckersDB] SET TRUSTWORTHY OFF 
GO
ALTER DATABASE [CheckersDB] SET ALLOW_SNAPSHOT_ISOLATION OFF 
GO
ALTER DATABASE [CheckersDB] SET PARAMETERIZATION SIMPLE 
GO
ALTER DATABASE [CheckersDB] SET READ_COMMITTED_SNAPSHOT OFF 
GO
ALTER DATABASE [CheckersDB] SET HONOR_BROKER_PRIORITY OFF 
GO
ALTER DATABASE [CheckersDB] SET RECOVERY SIMPLE 
GO
ALTER DATABASE [CheckersDB] SET  MULTI_USER 
GO
ALTER DATABASE [CheckersDB] SET PAGE_VERIFY CHECKSUM  
GO
ALTER DATABASE [CheckersDB] SET DB_CHAINING OFF 
GO
USE [CheckersDB]
GO
/****** Object:  Table [dbo].[GameMoves]    Script Date: 20/08/2013 22:35:43 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[GameMoves](
	[moveId] [int] IDENTITY(1,1) NOT NULL,
	[gameId] [int] NOT NULL,
	[playerId] [int] NOT NULL,
	[pieceId] [varchar](50) NOT NULL,
	[finalPositionPanelId] [int] NOT NULL,
	[timestamp] [datetime] NULL,
	[listOfRemovedPieces] [varchar](50) NULL,
	[isKing] [bit] NOT NULL,
 CONSTRAINT [PK_GameMoves] PRIMARY KEY CLUSTERED 
(
	[moveId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[GameRoomClients]    Script Date: 20/08/2013 22:35:43 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[GameRoomClients](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[gameId] [int] NOT NULL,
	[playerId] [int] NOT NULL,
	[playerType] [int] NOT NULL,
 CONSTRAINT [PK_GameRoomClients] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[GameRooms]    Script Date: 20/08/2013 22:35:43 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[GameRooms](
	[gameId] [int] IDENTITY(1,1) NOT NULL,
	[gameStatus] [int] NOT NULL,
	[isOccupiedBy] [int] NOT NULL,
	[timestamp] [datetime] NULL,
 CONSTRAINT [PK_GameRooms] PRIMARY KEY CLUSTERED 
(
	[gameId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[Players]    Script Date: 20/08/2013 22:35:43 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Players](
	[playerId] [int] IDENTITY(1,1) NOT NULL,
	[playerName] [varchar](50) NOT NULL,
	[playerUsername] [varchar](50) NOT NULL,
	[playerPassword] [varchar](50) NOT NULL,
 CONSTRAINT [PK_Players] PRIMARY KEY CLUSTERED 
(
	[playerId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Winners]    Script Date: 20/08/2013 22:35:43 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Winners](
	[gameWinnerId] [int] IDENTITY(1,1) NOT NULL,
	[gameId] [int] NULL,
	[playerId] [int] NULL,
 CONSTRAINT [PK_Winners] PRIMARY KEY CLUSTERED 
(
	[gameWinnerId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
ALTER TABLE [dbo].[GameMoves]  WITH CHECK ADD  CONSTRAINT [FK_GameMoves_GameRooms] FOREIGN KEY([gameId])
REFERENCES [dbo].[GameRooms] ([gameId])
GO
ALTER TABLE [dbo].[GameMoves] CHECK CONSTRAINT [FK_GameMoves_GameRooms]
GO
ALTER TABLE [dbo].[GameMoves]  WITH CHECK ADD  CONSTRAINT [FK_GameMoves_Players] FOREIGN KEY([playerId])
REFERENCES [dbo].[Players] ([playerId])
GO
ALTER TABLE [dbo].[GameMoves] CHECK CONSTRAINT [FK_GameMoves_Players]
GO
ALTER TABLE [dbo].[GameRoomClients]  WITH CHECK ADD  CONSTRAINT [FK_GameRoomClients_GameRooms] FOREIGN KEY([gameId])
REFERENCES [dbo].[GameRooms] ([gameId])
GO
ALTER TABLE [dbo].[GameRoomClients] CHECK CONSTRAINT [FK_GameRoomClients_GameRooms]
GO
ALTER TABLE [dbo].[GameRoomClients]  WITH CHECK ADD  CONSTRAINT [FK_GameRoomClients_Players] FOREIGN KEY([playerId])
REFERENCES [dbo].[Players] ([playerId])
GO
ALTER TABLE [dbo].[GameRoomClients] CHECK CONSTRAINT [FK_GameRoomClients_Players]
GO
ALTER TABLE [dbo].[Winners]  WITH CHECK ADD  CONSTRAINT [FK_Winners_GameRooms] FOREIGN KEY([gameId])
REFERENCES [dbo].[GameRooms] ([gameId])
GO
ALTER TABLE [dbo].[Winners] CHECK CONSTRAINT [FK_Winners_GameRooms]
GO
ALTER TABLE [dbo].[Winners]  WITH CHECK ADD  CONSTRAINT [FK_Winners_Players] FOREIGN KEY([playerId])
REFERENCES [dbo].[Players] ([playerId])
GO
ALTER TABLE [dbo].[Winners] CHECK CONSTRAINT [FK_Winners_Players]
GO
USE [master]
GO
ALTER DATABASE [CheckersDB] SET  READ_WRITE 
GO
